package com.javaziliao.design.dprecated.state;

import com.javaziliao.design.utils.RedisCommonProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

// 订单状态具体类，收货
@Component
public class DeprecatedReceiveOrder extends DeprecatedAbstractOrderState {
    @Autowired
    private RedisCommonProcessor redisCommonProcessor;

    @Override
    public DeprecatedOrder receiveOrder(String orderId, DeprecatedOrderContext context) {
        // 订单签收成功后，将订单状态设置为订单完成
        DeprecatedOrder order = (DeprecatedOrder) redisCommonProcessor.get(orderId);
        if (!order.getState().equals(ORDER_WAIT_RECEIVE)) {
            throw new UnsupportedOperationException("订单状态应该为待收货，当前状态为：" + order.getState());
        }
        order.setState(ORDER_FINISH);
        redisCommonProcessor.remove(orderId);
        super.notifyObserver(orderId,ORDER_FINISH);
        return order;
    }
}
